<template>
  <div
      v-show="visible"
      class="float-menu"
      :style="{left: x + 'px', top: y + 'px', width: menuWidth + 'px'}"
      @contextmenu.prevent.stop
  >
    <div
        class="menuItem"
        v-for="menu in menus"
        :key="JSON.stringify(menu)"
        @contextmenu.prevent.stop
    >
      <el-button
          @contextmenu.prevent.stop
          size="mini"
          :icon="menu.icon"
          @click="menu.callback(menu)"
          style="width: 100%;"
      >
        <slot :menu="menu">
          {{menu.name}}
        </slot>
      </el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "FloatMenu",
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    x: {
      type: Number,
      required: true,
      default: () => 0
    },
    y: {
      type: Number,
      required: true,
      default: () => 0
    },
    menus: {
      type: Array,
      required: true
    },
    menuWidth: {
      type: Number,
      required: false,
      default: () => 120
    },
    menuItemHeight: {
      type: Number,
      required: false,
      default: () => 24
    }
  }
}
</script>

<style scoped>
.float-menu {
  position: absolute;
  z-index: 9999;
}

.menuItem {
  width: 100%;
  text-align: center;
}
</style>